<template>
  <el-dialog
    title="审核台账"
    :close-on-click-modal="false"
    :visible.sync="visible"
    width="30%"
  >
    <el-form
      :model="auditForm"
      :rules="auditRule"
      ref="auditForm"
      label-width="162px"
    >
      <el-form-item label="审核结果" prop="audit">
        <el-select
          style="width:100%"
          v-model="auditForm.audit"
          placeholder="请选择审核结果"
        >
          <el-option label="通过" :value="1"> </el-option>
          <el-option label="不通过" :value="2"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否空车" prop="nullCar">
        <el-select
          style="width:100%"
          v-model="auditForm.nullCar"
          placeholder="请选择是否空车"
        >
          <el-option label="是" :value="1"> </el-option>
          <el-option label="否" :value="0"> </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="audit">审 核</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  components: {},

  data() {
    return {
      visible: false,
      id: null,
      auditForm: {},
      auditRule: {
        audit: [
          { required: true, message: "审核结果不能为空", trigger: "change" }
        ],
        nullCar: [
          { required: true, message: "是否空车不能为空", trigger: "change" }
        ]
      }
    };
  },
  watch: {},
  computed: {},
  created() {},
  mounted() {},
  methods: {
    init(id, flag, row) {
      this.id = id;
      this.visible = true;
      if (flag === "batch") {
        this.auditForm = {
          audit: null,
          nullCar: null
        };
      } else {
        this.auditForm = {
          audit: row.audit,
          nullCar: row.nullCar
        };
      }
    },
    audit() {
      this.$refs["auditForm"].validate(valid => {
        if (valid) {
          let params = [];
          this.id.forEach(item => {
            params.push({
              id: item,
              audit: this.auditForm.audit,
              nullCar: this.auditForm.nullCar
            });
          });
          this.$http({
            url: this.$http.adornUrl(`/generator/bcarledger/audit`),
            method: "post",
            data: this.$http.adornData({ arr: params })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: "审核成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    }
  }
};
</script>

<style scoped lang="scss"></style>
